cmake_minimum_required(VERSION 3.0)
project(clockys)

set (CMAKE_CXX_STANDARD 11)
# standalone build
if (CMAKE_CURRENT_LIST_DIR STREQUAL CMAKE_SOURCE_DIR)
	option (WITH_GLOG "build with glog" ON)
	if (WITH_GLOG)
		set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake_modules/")
		find_package(Glog)
	endif()
endif ()

option (WITH_EXAMPLE "build with example" OFF)
option (VERBOSE "output some message" OFF)

add_library(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/src/clockys.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC
	$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
	$<INSTALL_INTERFACE:include>)

if (GLOG_FOUND)
	target_include_directories(${PROJECT_NAME} PUBLIC
		${GLOG_INCLUDE_DIRS})
	target_link_libraries(${PROJECT_NAME} PUBLIC
		${GLOG_LIBRARY})
	target_compile_definitions(${PROJECT_NAME} PUBLIC
		USE_GLOG)
endif ()
if (VERBOSE)
	target_compile_definitions(${PROJECT_NAME} PRIVATE
		VERBOSE)
endif()

if (WITH_EXAMPLE)
	add_executable(test_${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/test/test.cpp)
	target_link_libraries(test_${PROJECT_NAME}
		${PROJECT_NAME}
		)
	set_target_properties(test_${PROJECT_NAME} PROPERTIES
		INSTALL_RPATH lib)
	install(TARGETS test_${PROJECT_NAME}
		RUNTIME DESTINATION bin)
endif()

install(TARGETS ${PROJECT_NAME}
	ARCHIVE DESTINATION lib
	LIBRARY DESTINATION lib)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/clockys
	DESTINATION include)

set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "for timing convinience")
set(CPACK_PACKAGE_VENDOR "taogashi")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "1")
include(CPack)
